package com.shop2cn.app.liveseller.testcase;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymttest.utils.TestDataManager;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*商品置顶
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetLiveProductTop{
	private static SetLiveProductTopBean setliveproducttopBean;
	private static SetLiveProductTopCall setliveproducttopCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品置顶");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(
					sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		setliveproducttopBean=new SetLiveProductTopBean();
		setliveproducttopCall=new SetLiveProductTopCall();
		LiveRoomShop2cnWapper=new LiveRoomShop2cnWapper();
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setliveproducttopCall.getOpurl());
		LiveRoomShop2cnWapper=null;
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetLiveProductTop_001() {
		Logger.start(true,"status0未开始商品置顶失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(createlive.getId());
			
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("201", setliveproducttopCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播未开始，无法置顶直播", setliveproducttopCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveProductTop_002() {
		Logger.start(true,"不输入liveid失败");
		try {
//			List<Userinfo> list = new JUserWapper().select1KSeller();
//			Userinfo uinfo = list.get(0);
//			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
//			
//			Logger.comment("创建商品：" + pid);
//			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(uinfo));
//			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			new LiveRoomShop2cnWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-5), null, createlive.getId());
			
//			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(TestDataManager.getRandomUUID().toString());
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("400", setliveproducttopCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播Id参数错误", setliveproducttopCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveProductTop_003() {
		Logger.start(true,"不输入ProductId失败");
		try {
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
//			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(createlive.getId());
			setliveproducttopBean.setLiveId(createlive.getId());
//			setliveproducttopBean.setProductId(TestDataManager.getRandomUUID().toString());
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("400", setliveproducttopCall.getString("code"), "验证Code");
			Logger.verifyEquals("商品Id不能为空", setliveproducttopCall.getString("msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetLiveProductTop_004() {
		Logger.start(true,"输入错误ProductId,不会设置");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid+1);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("{}", setliveproducttopCall.getReturnData(), "验证Code");
			List<Map> top = LiveRoomShop2cnWapper.selectTopLiveproductByLiveid(createlive.getId());
			Logger.debug(top);
			Logger.verifyEquals(0,top.size(), "验证没有top");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetLiveProductTop_005() {
		Logger.start(true,"status2已经推流直播商品置顶成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("{}", setliveproducttopCall.getReturnData(), "验证Code");
			List<Map> top = LiveRoomShop2cnWapper.selectTopLiveproductByLiveid(createlive.getId());
			Logger.debug(top);
			Logger.verifyEquals(1,top.size(), "验证只有一个top");
			Logger.verifyEquals(pid,top.get(0).get("ProductId"), "验证pid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetLiveProductTop_006() {
		Logger.start(true,"status3已经断流直播商品置顶成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			StreamLiveNotifyBean streamlivenotifyBean = LiveRoomShop2cnCallService.initStreamLiveNotifyBean(createlive.getId(), 0);
			LiveRoomShop2cnCallService.LiveNotify(streamlivenotifyBean);
			
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("{}", setliveproducttopCall.getReturnData(), "验证Code");
			List<Map> top = LiveRoomShop2cnWapper.selectTopLiveproductByLiveid(createlive.getId());
			Logger.debug(top);
			Logger.verifyEquals(1,top.size(), "验证只有一个top");
			Logger.verifyEquals(pid,top.get(0).get("ProductId"), "验证pid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_SetLiveProductTop_007() {
		Logger.start(true,"status7系统自动关闭置顶失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("{}", setliveproducttopCall.getReturnData(), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_SetLiveProductTop_008() {
		Logger.start(true,"status8未推流关闭直播置顶失败");
		try {
			//此处关闭时候会把所有商品设置成暂停销售
			org.junit.Assert.fail();
			setliveproducttopCall.setData(setliveproducttopBean);
			setliveproducttopCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_SetLiveProductTop_009() {
		Logger.start(true,"status9已推流结束直播置顶失败");
		try {
			//此处关闭时候会把所有商品设置成暂停销售
			org.junit.Assert.fail();
			setliveproducttopCall.setData(setliveproducttopBean);
			setliveproducttopCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_SetLiveProductTop_010() {
		Logger.start(true,"status10运营强制关停排序失败");
		try {
			//此处关闭时候会把所有商品设置成暂停销售
			org.junit.Assert.fail();
			setliveproducttopCall.setData(setliveproducttopBean);
			setliveproducttopCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetLiveProductTop_011() {
		Logger.start(true,"status1待开始商品置顶失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+token;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("201", setliveproducttopCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播未开始，无法置顶直播", setliveproducttopCall.getString("msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetLiveProductTop_012() {
		Logger.start(true,"客服直播商品置顶成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId, "autotest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), Arrays.asList(pid));
			LiveRoomShop2cnCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			setliveproducttopBean.setLiveId(createlive.getId());
			setliveproducttopBean.setProductId(pid);
			setliveproducttopCall.setData(setliveproducttopBean);
			String head="accesstoken="+cstoken;
			setliveproducttopCall.addHeader("ymt-pars", head);
			setliveproducttopCall.callService();			
			Logger.verifyEquals("{}", setliveproducttopCall.getReturnData(), "验证Code");
			List<Map> top = LiveRoomShop2cnWapper.selectTopLiveproductByLiveid(createlive.getId());
			Logger.debug(top);
			Logger.verifyEquals(1,top.size(), "验证只有一个top");
			Logger.verifyEquals(pid,top.get(0).get("ProductId"), "验证pid");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}